package cn.git.http.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @description: httpController测试接口
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2025-08-13
 */
@Slf4j
@RestController
@RequestMapping("/http")
public class HttpController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/getHttpInfo")
    public String getHttpInfo() {
        log.info("getHttpInfo");
        return "http";
    }

    /**
     * GET获取https服务信息
     *
     * @return
     */
    @GetMapping("/getHttpsInfo")
    public String getHttpsInfo() {
        return restTemplate.getForObject("https://3.2.36.116:443/https/getHttpsInfo", String.class);
    }

    /**
     * POST获取https服务信息
     *
     * @return
     */
    @GetMapping("/getPostHttpsInfo")
    public String getPostHttpsInfo() {
        String requestBody = "{\"id\":\"1\",\"name\": \"jack\"}";

        // 创建请求头，设置Content-Type为JSON
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 创建HttpEntity
        HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);

        // POST请求，调用https服务
        return restTemplate.postForObject("https://3.2.36.116:443/https/getPostHttpsInfo", requestEntity, String.class);
    }
}
